package falstad;

public class WizardRobotDriver implements RobotDriver {

	private Robot robot;
	float startingBattery;
	
	public WizardRobotDriver(Robot r)
	{
		this.robot = r;
		startingBattery = getEnergyConsumption();
	}
	
	
	@Override
	public void setRobot(Robot r) throws UnsuitableRobotException {
		this.robot = r;

	}

	@Override
	public boolean drive2Exit() throws Exception {
		while (!robot.isAtGoal() && robot.getCurrentBatteryLevel()!=0)
		{
			//robot.printCurrentInfo();
			robot.move(1, true);
		}
		if (robot.isAtGoal())
		{
			return true;
		}
		else 
		{
			throw(new Exception());
			//return false;
		}
		
	}

	@Override
	public float getEnergyConsumption() {
		
		return startingBattery - robot.getCurrentBatteryLevel() ;
	}

	@Override
	public int getPathLength() {
		return robot.getDistTraveled();
	}

}
